using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Xid.Controls
{
      public sealed class ContextColorMgr
    {
 
        #region Singleton pattern
          static readonly ContextColorMgr instance = new ContextColorMgr();

        static ContextColorMgr()
        {
        }

          ContextColorMgr()
        {

            colorMapping = new Dictionary<string, Color>();
            Map("Quantity");
            Map("ResponseRange");
            Map("FreeText");
            Map("Quality");
        }

          public static ContextColorMgr Instance
        {
            get
            {
                return instance;
            }
        }
        #endregion


        private Color[] contextColors = new Color[] { Color.Blue, Color.Green, Color.Orange, Color.Yellow, Color.Red };
        private Dictionary<string, Color> colorMapping;


          public Color Map(string context)
          {
              if(this.colorMapping.ContainsKey(context))
              {
                  return this.colorMapping[context];
              }


              if (this.colorMapping.Count + 1 > contextColors.Length)
              {
                  Random rand = new Random();
                  int r = rand.Next(0, 255);
                  int g = rand.Next(0, 255);
                  int b = rand.Next(0, 255);
                  this.colorMapping.Add(context,Color.FromArgb(r,g,b));
              }
              else
              {
                  this.colorMapping.Add(context, contextColors[colorMapping.Count]);

              }
              return this.colorMapping[context];
          }
    }
}
